package com.whalehearing.tingyou.web.controller.hearing;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.domain.HearingInitialValuation;
import com.whalehearing.tingyou.service.IHearingInitialValuationService;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;

/**
 * 测前初评Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-14
 */
@Api(tags="测前初评管理")
@RestController
@RequestMapping("system/hearing/valuation")
public class HearingInitialValuationController extends BaseController
{
    @Autowired
    private IHearingInitialValuationService hearingInitialValuationService;

    /**
     * 查询测前初评列表
     */
    @ApiOperation("查询测前初评列表")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingInitialValuation hearingInitialValuation)
    {
        startPage();
        List<HearingInitialValuation> list = hearingInitialValuationService.selectHearingInitialValuationList(hearingInitialValuation);
        return getDataTable(list);
    }

    /**
     * 导出测前初评列表
     */
    @ApiOperation("导出测前初评列表")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:export')")
    @Log(title = "测前初评", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingInitialValuation hearingInitialValuation)
    {
        List<HearingInitialValuation> list = hearingInitialValuationService.selectHearingInitialValuationList(hearingInitialValuation);
        ExcelUtil<HearingInitialValuation> util = new ExcelUtil<HearingInitialValuation>(HearingInitialValuation.class);
        util.exportExcel(response, list, "测前初评数据");
    }

    /**
     * 获取测前初评详细信息
     */
    @ApiOperation("获取测前初评详细信息")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:query')")
    @GetMapping(value = "/{initialValuationId}")
    public AjaxResult getInfo(@PathVariable("initialValuationId") Long initialValuationId)
    {
        return success(hearingInitialValuationService.getById(initialValuationId));
    }

    /**
     * 新增测前初评
     */
    @ApiOperation("新增测前初评")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:add')")
    @Log(title = "测前初评", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingInitialValuation hearingInitialValuation)
    {
        return toAjax(hearingInitialValuationService.save(hearingInitialValuation));
    }

    /**
     * 修改测前初评
     */
    @ApiOperation("修改测前初评")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:edit')")
    @Log(title = "测前初评", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingInitialValuation hearingInitialValuation)
    {
        return toAjax(hearingInitialValuationService.updateById(hearingInitialValuation));
    }

    /**
     * 删除测前初评
     */
    @ApiOperation("删除测前初评")
    @PreAuthorize("@ss.hasPermi('hearing:valuation:remove')")
    @Log(title = "测前初评", businessType = BusinessType.DELETE)
	@DeleteMapping("/{initialValuationIds}")
    public AjaxResult remove(@PathVariable Long[] initialValuationIds)
    {
        return toAjax(hearingInitialValuationService.removeByIds(Arrays.asList(initialValuationIds)));
    }
}
